define('admin/js/mod/user/ListCreditLog', [
    'utils/fetchEnhancer',
    'utils/Time',
    'utils/helpers'], (fetch, Time, helpers) => {

Vue.prototype.Time = Time;

const ListCreditLog = {
    data: function() {
        return {
            searchForm: {uid: ''},
            list: null,
            total: 0,
            pageSize: 10,
            current: 1
        }
    },
    methods: {
        fetchList: function(page) {
            let _self = this;
            let uid = this.searchForm.uid;

            fetch('/adminapi/listusercreditlog?page=' + page + '&uid=' + uid).then(function(json){
                if(0 === json.status) {
                    _self.total = parseInt(json.data.total, 10);
                    _self.pageSize = parseInt(json.data.page_size, 10);
                    _self.current = parseInt(json.data.current, 10);
                    _self.list = json.data.data;
                }
            });
        },
        pageChange: function(p) {
            this.fetchList(p);
        },
        doSearch: function() {
            this.fetchList(1);
        }
    },
    mounted: function() {
        this.fetchList(1);
    },
    template:
`<div>
    <el-form :inline="true" size="medium">
        <el-form-item label="">
            <el-input v-model="searchForm.uid" placeholder="输入uid搜索"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="doSearch">查询</el-button>
        </el-form-item>
    </el-form>
    <table class="x-table">
        <tr>
            <th>uid</th>
            <th>金钱</th>
            <th>积分</th>
            <th>经验</th>
            <th>行为</th>
            <th>说明</th>
            <th>时间</th>
        </tr>
        <template v-if="list && list.length">
            <tr v-for="item in list">
                <td>{{ item.uid }}</td>
                <td>{{ item.money }}</td>
                <td>{{ item.score }}</td>
                <td>{{ item.experience }}</td>
                <td>{{ item.action_text }}</td>
                <td>{{ item.reason }}</td>
                <td>{{ Time.format('y-m-d h:i', item.log_time * 1000) }}</td>
            </tr>
        </template>
    </table>

    <div style="margin-top: 10px; text-align: right">
        <el-pagination
            background
            layout="prev, pager, next"
            @current-change="pageChange"
            :current-page="current"
            :page-size="pageSize"
            :total="total">
        </el-pagination>
    </div>
</div>`
};

return ListCreditLog;

});
